﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using Meeting.Public;
using Newtonsoft.Json;

namespace Meeting.Web.Admin.BaseSet
{
    /// <summary>
    ///  模块功能：角色相关操作，角色创建 角色查询、角色分组创建，角色分组关联等功能
    ///  模块作者：吴龙波
    ///  模块日期：20130116
    /// </summary>
    public class RoleOperation : IHttpHandler
    {

        string methodName = "";
        int nPageIndex = 1;
        int nPageSize = 20;
        public void ProcessRequest(HttpContext context)
        {
            context.Response.ContentType = "application/json;charset=utf-8";
            methodName = context.Request.Params["method"];
            nPageIndex = CommonFunction.varToIntDef(context.Request.Params["page"], 1);
            nPageSize = CommonFunction.varToIntDef(context.Request.Params["rows"], 15);

            switch (methodName)
            {
                case "GetRole":   //获取json数据
                    GetRole(context);
                    break;
                case "RoleEdit":
                    RoleEdit(context);
                    break;
            }
        }
        BLL.Role bll = new BLL.Role();
        private void GetRole(HttpContext context)
        {
            ////获取已有的role数据
            string str = bll.GetRoleJson(nPageIndex, nPageSize, "");
            context.Response.Write(str);
        }
        //角色数据编辑
        private void RoleEdit(HttpContext context)
        {            
            Model.JsonResponse jr = new Model.JsonResponse();
            Model.Role model = new Model.Role();
            model.Id = context.Request["Id"];
            model.Name = context.Request["Name"];
            model.Comment = context.Request["Comment"];
            //
            if (bll.RoleEdit(model))
            {
                jr.success = true;
            }
            else {
                jr.success = false;
                jr.Message = bll.errorString;
            }
            context.Response.Write(JsonConvert.SerializeObject(jr));
        }

        public bool IsReusable
        {
            get
            {
                return false;
            }
        }
    }
}